# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#作者：cacho_37967865
#博客：https://blog.csdn.net/sinat_37967865
#文件：Sudoku.py
#日期：2024-03-09
#备注：数独填空
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

def deal_su_do():
    su_du = []
    for i in range(9):
        temp = []
        for j in range(9):
            temp.append(0)
        su_du.append(temp)
    su_du[0][0] =9
    su_du[0][1] = 4
    su_du[0][3] = 8
    su_du[0][6] = 6
    su_du[0][8] = 2
    su_du[1][2] = 3
    su_du[1][6] = 5
    su_du[1][7] = 8
    su_du[2][1] = 2
    su_du[2][2] = 1
    su_du[2][5] = 3
    su_du[3][3] = 3
    su_du[3][5] = 6
    su_du[4][2] = 4
    su_du[4][3] = 2
    su_du[4][7] = 7
    su_du[5][3] = 7
    su_du[5][5] = 5
    su_du[6][1] = 3
    su_du[6][3] = 4
    su_du[6][7] = 5
    su_du[7][1] = 8
    su_du[7][6] = 3
    su_du[8][0] = 5
    su_du[8][2] = 6
    su_du[8][8] = 7
    #print (su_du)
    return su_du

def get_H(n):
    print("横：",deal_su_do()[n])
    return deal_su_do()[n]

def get_L(n):
    L_list = []
    for i in range(9):
        temp = []
        for j in range(9):
            temp.append(deal_su_do()[j][i])
        L_list.append(temp)
    print("竖：",L_list[n] )
    return L_list[n]

def get_table(h1,l1):
    #print(deal_su_do())
    t_list = []
    for i in range(9):
        t = []
        for j in range(9):
            temp = []
            for h in range(3):
                for l in range(3):
                    temp.append(deal_su_do()[int(i/3)*3+h][int(j/3)*3+l])
                    #print(i,j,"hl",int(i/3)+h,int(j/3)*3+l,temp)
            t.append(temp)
        t_list.append(t)
    print("方框：", h1, l1, t_list[h1][l1])
    #print(t_list[h1][l1])
    return t_list[h1][l1]


def insert():
    for i in range(9):
        for j in range(9):
            temp = []
            if deal_su_do()[i][j]==0:
                for k in range(1,10):
                    print("选择：", i, j, k)
                    if k not in get_H(i) and k not in get_L(j) and k not in get_table(i,j):
                        temp.append(k)
                print("填充：",i,j,temp)


if __name__ == '__main__':
    #get_H(1)
    #get_L(1)
    #print(deal_su_do())
    #get_table(5,3)
    insert()